<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.student_no" clearable placeholder="学号" style="width: 150px" class="filter-item"/>
      <el-input v-model="listQuery.realname" clearable placeholder="姓名" style="width: 150px" class="filter-item"/>
      <el-input v-model="listQuery.zhuanye" clearable placeholder="专业" style="width: 150px" class="filter-item"/>
      <el-input v-model="listQuery.class" clearable placeholder="班级" style="width: 150px" class="filter-item"/>
      <el-select v-model="listQuery.grade" clearable placeholder="年级" class="filter-item">
        <el-option v-for="(value, index) in grade" :key="index" :value="index" :label="value"/>
      </el-select>
      <el-select v-model="listQuery.house_id" clearable placeholder="宿舍楼栋" class="filter-item" @change="handleChangeHouse(listQuery.house_id)">
        <el-option v-for="(value, index) in house" :key="index" :value="index" :label="value"/>
      </el-select>
      <el-select v-model="listQuery.sushe_id" clearable placeholder="宿舍号" class="filter-item">
        <el-option v-for="(value, index) in room" :key="index" :value="index" :label="value"/>
      </el-select>
      <el-button type="primary" class="filter-item" @click="handleFilter">搜索</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border highlight-current-row>
      <el-table-column label="ID">
        <template slot-scope="scope">{{ scope.row.uid }}</template>
      </el-table-column>
      <el-table-column label="学号">
        <template slot-scope="scope">{{ scope.row.student_no }}</template>
      </el-table-column>
      <el-table-column label="姓名">
        <template slot-scope="scope">{{ scope.row.realname }}</template>
      </el-table-column>
      <el-table-column label="专业">
        <template slot-scope="scope">{{ scope.row.zhuanye }}</template>
      </el-table-column>
      <el-table-column label="年级">
        <template slot-scope="scope">{{ scope.row.grade }}</template>
      </el-table-column>
      <el-table-column label="班级">
        <template slot-scope="scope">{{ scope.row.class }}</template>
      </el-table-column>
      <el-table-column label="宿舍">
        <template slot-scope="scope">{{ scope.row.house_room }}</template>
      </el-table-column>
      <el-table-column label="电话">
        <template slot-scope="scope">{{ scope.row.mobile }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <router-link :to="{path:'/member/edit',query:{id: scope.row.uid}}">
            <el-button type="success" size="mini">详情</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getList } from '@/api/member'
import { getRoomByHouseId } from '@/api/room'
export default {
  name: 'Index',
  components: { Pagination },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 20,
        student_no: '',
        realname: '',
        zhuanye: '',
        class: '',
        grade: '',
        house_id: '',
        sushe_id: ''
      },
      total: 0,
      house: [], // 楼栋
      room: [], // 宿舍
      grade: [],
      listLoading: true,
      list: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      getList(this.listQuery).then(res => {
        this.listLoading = false
        this.list = res.data.list
        this.total = res.data.total
        this.house = res.data.house
        this.grade = res.data.grade
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fetchData()
    },
    handleChangeHouse(house_id) {
      getRoomByHouseId({ id: house_id }).then(res => {
        this.room = res.data
      })
    }

  }
}
</script>

<style scoped>

</style>
